home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / uno.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  14KB  |  378 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import sys
  6. sys.path.append('/usr/lib/openoffice/basis-link/program')
  7. if getattr(os.environ, 'URE_BOOTSTRAP', None) is None:
  8.     os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:/usr/lib/openoffice/program/fundamentalrc'
  9.  
  10. import pyuno
  11. import __builtin__
  12. import socket
  13. _g_ctx = pyuno.getComponentContext()
  14. _g_delegatee = __builtin__.__dict__['__import__']
  15.  
  16. def getComponentContext():
  17.     ''' returns the UNO component context, that was used to initialize the python runtime.
  18.     '''
  19.     return _g_ctx
  20.  
  21.  
  22. def getConstantByName(constant):
  23.     '''Looks up the value of a idl constant by giving its explicit name'''
  24.     return pyuno.getConstantByName(constant)
  25.  
  26.  
  27. def getTypeByName(typeName):
  28.     ''' returns a uno.Type instance of the type given by typeName. In case the
  29.         type does not exist, a com.sun.star.uno.RuntimeException is raised.
  30.     '''
  31.     return pyuno.getTypeByName(typeName)
  32.  
  33.  
  34. def createUnoStruct(typeName, *args):
  35.     '''creates a uno struct or exception given by typeName. The parameter args may
  36.     1) be empty. In this case, you get a default constructed uno structure.
  37.        ( e.g. createUnoStruct( "com.sun.star.uno.Exception" ) )
  38.     2) be a sequence with exactly one element, that contains an instance of typeName.
  39.        In this case, a copy constructed instance of typeName is returned
  40.        ( e.g. createUnoStruct( "com.sun.star.uno.Exception" , e ) )
  41.     3) be a sequence, where the length of the sequence must match the number of
  42.        elements within typeName (e.g.
  43.        createUnoStruct( "com.sun.star.uno.Exception", "foo error" , self) ). The
  44.        elements with in the sequence must match the type of each struct element,
  45.        otherwise an exception is thrown.
  46.     '''
  47.     return getClass(typeName)(*args)
  48.  
  49.  
  50. def getClass(typeName):
  51.     '''returns the class of a concrete uno exception, struct or interface
  52.     '''
  53.     return pyuno.getClass(typeName)
  54.  
  55.  
  56. def isInterface(obj):
  57.     '''returns true, when obj is a class of a uno interface'''
  58.     return pyuno.isInterface(obj)
  59.  
  60.  
  61. def generateUuid():
  62.     '''returns a 16 byte sequence containing a newly generated uuid or guid, see rtl/uuid.h '''
  63.     return pyuno.generateUuid()
  64.  
  65.  
  66. def systemPathToFileUrl(systemPath):
  67.     '''returns a file-url for the given system path'''
  68.     return pyuno.systemPathToFileUrl(systemPath)
  69.  
  70.  
  71. def fileUrlToSystemPath(url):
  72.     '''returns a system path (determined by the system, the python interpreter is running on)'''
  73.     return pyuno.fileUrlToSystemPath(url)
  74.  
  75.  
  76. def absolutize(path, relativeUrl):
  77.     '''returns an absolute file url from the given urls'''
  78.     return pyuno.absolutize(path, relativeUrl)
  79.  
  80.  
  81. def getCurrentContext():
  82.     '''Returns the currently valid current context.
  83.        see http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
  84.        for an explanation on the current context concept
  85.     '''
  86.     return pyuno.getCurrentContext()
  87.  
  88.  
  89. def setCurrentContext(newContext):
  90.     '''Sets newContext as new uno current context. The newContext must
  91.     implement the XCurrentContext interface. The implemenation should
  92.     handle the desired properties and delegate unknown properties to the
  93.     old context. Ensure to reset the old one when you leave your stack ...
  94.     see http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
  95.     '''
  96.     return pyuno.setCurrentContext(newContext)
  97.  
  98.  
  99. class Enum:
  100.     '''Represents a UNO idl enum, use an instance of this class to explicitly pass a boolean to UNO'''
  101.     
  102.     def __init__(self, typeName, value):
  103.         self.typeName = typeName
  104.         self.value = value
  105.         pyuno.checkEnum(self)
  106.  
  107.     
  108.     def __repr__(self):
  109.         return '<uno.Enum %s (%r)>' % (self.typeName, self.value)
  110.  
  111.     
  112.     def __eq__(self, that):
  113.         return isinstance(that, Enum) if not isinstance(that, Enum) else self.value == that.value
  114.  
  115.  
  116.  
  117. class Type:
  118.     '''Represents a UNO type, use an instance of this class to explicitly pass a boolean to UNO'''
  119.     
  120.     def __init__(self, typeName, typeClass):
  121.         self.typeName = typeName
  122.         self.typeClass = typeClass
  123.         pyuno.checkType(self)
  124.  
  125.     
  126.     def __repr__(self):
  127.         return '<Type instance %s (%r)>' % (self.typeName, self.typeClass)
  128.  
  129.     
  130.     def __eq__(self, that):
  131.         return isinstance(that, Type) if not isinstance(that, Type) else self.typeName == that.typeName
  132.  
  133.     
  134.     def __hash__(self):
  135.         return self.typeName.__hash__()
  136.  
  137.  
  138.  
  139. class Bool(object):
  140.     """Represents a UNO boolean, use an instance of this class to explicitly 
  141.        pass a boolean to UNO.
  142.        Note: This class is deprecated. Use python's True and False directly instead
  143.     """
  144.     
  145.     def __new__(cls, value):
  146.         if isinstance(value, (str, unicode)) and value == 'true':
  147.             return True
  148.         if isinstance(value, (str, unicode)) and value == 'false':
  149.             return False
  150.         if value:
  151.             return True
  152.         return False
  153.  
  154.  
  155.  
  156. class Char:
  157.     '''Represents a UNO char, use an instance of this class to explicitly pass a char to UNO'''
  158.     
  159.     def __init__(self, value):
  160.         if not isinstance(value, unicode):
  161.             raise AssertionError
  162.         if not len(value) == 1:
  163.             raise AssertionError
  164.         self.value = value
  165.  
  166.     
  167.     def __repr__(self):
  168.         return '<Char instance %s>' % (self.value,)
  169.  
  170.     
  171.     def __eq__(self, that):
  172.         if isinstance(that, (str, unicode)):
  173.             if len(that) > 1:
  174.                 return False
  175.             return self.value == that[0]
  176.         if isinstance(that, Char):
  177.             return self.value == that.value
  178.         return False
  179.  
  180.  
  181.  
  182. class ByteSequence:
  183.     
  184.     def __init__(self, value):
  185.         if isinstance(value, str):
  186.             self.value = value
  187.         elif isinstance(value, ByteSequence):
  188.             self.value = value.value
  189.         else:
  190.             raise TypeError('expected string or bytesequence')
  191.         return isinstance(value, str)
  192.  
  193.     
  194.     def __repr__(self):
  195.         return "<ByteSequence instance '%s'>" % (self.value,)
  196.  
  197.     
  198.     def __eq__(self, that):
  199.         if isinstance(that, ByteSequence):
  200.             return self.value == that.value
  201.         if isinstance(that, str):
  202.             return self.value == that
  203.         return False
  204.  
  205.     
  206.     def __len__(self):
  207.         return len(self.value)
  208.  
  209.     
  210.     def __getitem__(self, index):
  211.         return self.value[index]
  212.  
  213.     
  214.     def __iter__(self):
  215.         return self.value.__iter__()
  216.  
  217.     
  218.     def __add__(self, b):
  219.         if isinstance(b, str):
  220.             return ByteSequence(self.value + b)
  221.         if isinstance(b, ByteSequence):
  222.             return ByteSequence(self.value + b.value)
  223.         raise TypeError('expected string or ByteSequence as operand')
  224.  
  225.     
  226.     def __hash__(self):
  227.         return self.value.hash()
  228.  
  229.  
  230.  
  231. class Any:
  232.     '''use only in connection with uno.invoke() to pass an explicit typed any'''
  233.     
  234.     def __init__(self, type, value):
  235.         if isinstance(type, Type):
  236.             self.type = type
  237.         else:
  238.             self.type = getTypeByName(type)
  239.         self.value = value
  240.  
  241.  
  242.  
  243. def invoke(object, methodname, argTuple):
  244.     '''use this function to pass exactly typed anys to the callee (using uno.Any)'''
  245.     return pyuno.invoke(object, methodname, argTuple)
  246.  
  247.  
  248. def _uno_import(name, *optargs, **kwargs):
  249.     
  250.     try:
  251.         return _g_delegatee(name, *optargs, **kwargs)
  252.     except ImportError:
  253.         (globals, locals, fromlist) = list(optargs)[:3] + [
  254.             kwargs.get('globals', { }),
  255.             kwargs.get('locals', { }),
  256.             kwargs.get('fromlist', [])][len(optargs):]
  257.         if not fromlist:
  258.             raise 
  259.         fromlist
  260.  
  261.     modnames = name.split('.')
  262.     mod = None
  263.     d = sys.modules
  264.     for x in modnames:
  265.         if d.has_key(x):
  266.             mod = d[x]
  267.         else:
  268.             mod = pyuno.__class__(x)
  269.         d = mod.__dict__
  270.     
  271.     RuntimeException = pyuno.getClass('com.sun.star.uno.RuntimeException')
  272.     for x in fromlist:
  273.         if not d.has_key(x):
  274.             if x.startswith('typeOf'):
  275.                 
  276.                 try:
  277.                     d[x] = pyuno.getTypeByName(name + '.' + x[6:len(x)])
  278.                 except RuntimeException:
  279.                     e = None
  280.                     raise ImportError('type ' + name + '.' + x[6:len(x)] + ' is unknown')
  281.                 except:
  282.                     None<EXCEPTION MATCH>RuntimeException
  283.                 
  284.  
  285.             None<EXCEPTION MATCH>RuntimeException
  286.             
  287.             try:
  288.                 d[x] = pyuno.getClass(name + '.' + x)
  289.             except RuntimeException:
  290.                 e = None
  291.                 
  292.                 try:
  293.                     d[x] = Enum(name, x)
  294.                 except RuntimeException:
  295.                     e2 = None
  296.                     
  297.                     try:
  298.                         d[x] = getConstantByName(name + '.' + x)
  299.                     except RuntimeException:
  300.                         e3 = None
  301.                         raise ImportError('type ' + name + '.' + x + ' is unknown')
  302.                     except:
  303.                         None<EXCEPTION MATCH>RuntimeException
  304.                     
  305.  
  306.                     None<EXCEPTION MATCH>RuntimeException
  307.                 
  308.  
  309.                 None<EXCEPTION MATCH>RuntimeException
  310.             
  311.  
  312.         None<EXCEPTION MATCH>RuntimeException
  313.     
  314.     return mod
  315.  
  316. __builtin__.__dict__['__import__'] = _uno_import
  317.  
  318. def _impl_extractName(name):
  319.     r = range(len(name) - 1, 0, -1)
  320.     for i in r:
  321.         if name[i] == '.':
  322.             name = name[i + 1:len(name)]
  323.             break
  324.             continue
  325.     
  326.     return name
  327.  
  328.  
  329. def _uno_struct__init__(self, *args):
  330.     if len(args) == 1 and hasattr(args[0], '__class__') and args[0].__class__ == self.__class__:
  331.         self.__dict__['value'] = args[0]
  332.     else:
  333.         self.__dict__['value'] = pyuno._createUnoStructHelper(self.__class__.__pyunostruct__, args)
  334.  
  335.  
  336. def _uno_struct__getattr__(self, name):
  337.     return __builtin__.getattr(self.__dict__['value'], name)
  338.  
  339.  
  340. def _uno_struct__setattr__(self, name, value):
  341.     return __builtin__.setattr(self.__dict__['value'], name, value)
  342.  
  343.  
  344. def _uno_struct__repr__(self):
  345.     return repr(self.__dict__['value'])
  346.  
  347.  
  348. def _uno_struct__str__(self):
  349.     return str(self.__dict__['value'])
  350.  
  351.  
  352. def _uno_struct__eq__(self, cmp):
  353.     if hasattr(cmp, 'value'):
  354.         return self.__dict__['value'] == cmp.__dict__['value']
  355.     return False
  356.  
  357.  
  358. def _uno_extract_printable_stacktrace(trace):
  359.     mod = None
  360.     
  361.     try:
  362.         mod = __import__('traceback')
  363.     except ImportError:
  364.         e = None
  365.  
  366.     ret = ''
  367.     if mod:
  368.         lst = mod.extract_tb(trace)
  369.         max = len(lst)
  370.         for j in range(max):
  371.             i = lst[max - j - 1]
  372.             ret = ret + '  ' + str(i[0]) + ':' + str(i[1]) + ' in function ' + str(i[2]) + '() [' + str(i[3]) + ']\n'
  373.         
  374.     else:
  375.         ret = "Couldn't import traceback module"
  376.     return ret
  377.  
  378.